﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Reports.GoodsReport
{
    public partial class InputParamForm : Form,IntegrationInterface.IDIProjectForm
    {
        public InputParamForm()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #region IDIProjectForm Members
        private string _conStr;
        public string ConnectionString
        {
            get
            {
                return _conStr;
            }
            set
            {
                _conStr = value;
            }
        }
        private string _login;
        public string Login
        {
            get
            {
                return _login;
            }
            set
            {
                _login = value;
            }
        }

        public Form MailForm
        {
            get 
            {
                return this; 
            }
        }
        private object _obj;
        public object CommonProperty
        {
            get
            {
                return _obj;
            }
            set
            {
                _obj = value;
            }
        }

        #endregion
        /// <summary>
        /// печатаем отчет
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
          
                //Reports.Util.Common.RestToDate(this.ConnectionString, dtpDateT.Value);
            Reports.GoodsReport.DataSet data = new Reports.GoodsReport.DataSet();
            Reports.GoodsReport.DataSet.InfoRow ir = data.Info.NewInfoRow();
            ir.AptekaName = Reports.Util.Common.GetAptekaName(this.ConnectionString);
            ir.DateF = dtpDateF.Value.Date.AddSeconds(-1);
            ir.DateT = dtpDateT.Value.Date.AddDays(1).AddSeconds(-1);
            decimal bRest = Reports.Util.Common.RestToDate(this.ConnectionString, dtpDateF.Value.Date);
            Util.Data uData = new Reports.Util.Data(this.ConnectionString);
            decimal eRest = uData.SumFromDateE(ir.DateT, null, null);
            ir.RestBegin = bRest;
            ir.RestEnd = eRest;
            ir.Discount = uData.DiscountSum(ir.DateF, ir.DateT);
            data.Info.Rows.Add(ir);
            Reports.GoodsReport.DataLoader.GetInputData(data.DataInput, this.ConnectionString, ir.DateF, ir.DateT);
            Reports.GoodsReport.DataLoader.GetOutputData(data.DataOutput, this.ConnectionString, ir.DateF, ir.DateT);
            Reports.GoodsReport.PrintForm pf = new Reports.GoodsReport.PrintForm(
                data,
                0,
                bRest,
                eRest
                );
            string repPath = (string)this.CommonProperty;
            pf.InitReport(repPath);
            pf.MdiParent = this.MdiParent;
            pf.Show();

        }
    }
}